package cn.java75.sp.web;

import cn.java75.sp.conf.MailConfig;
import cn.java75.sp.entity.Admin;
import cn.java75.sp.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

/**
 * @author oldliu
 * @since 1.0
 */
@RestController
@ResponseBody
@RequestMapping("admin")
public class AdminController {

       @Autowired
    private MailConfig config;

    @Autowired
    @Qualifier("redisTemplate")//stringRedisTemplate
    private RedisTemplate redisTemplate;
    @PostMapping("login")
    public AjaxResult login(String name, String pass, HttpServletRequest request, HttpServletResponse resp){
        if(name.length()>5)
        {
            String token=UUID.randomUUID().toString();
            redisTemplate.opsForValue().set(token,new Admin((long) (Math.random()*1999),name,pass));
            return AjaxResult.success("login ok",token);
        }
        return AjaxResult.error("密码错误");

    }

    //@R
    @GetMapping("showmail")
    public String showMailConfig(){
        return String.valueOf(config);
    }
}
